<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>用户登录</title>
    <meta name="_token" content="{{ csrf_token() }}"/>
    <link rel="stylesheet" href="/static/public/layui/css/layui.css">
    <link rel="stylesheet" href="/static/home/css/style.css">
    <script type="text/javascript" src="/static/public/layui/layui.js"></script>
</head>
<body>
<div class="layui-form">
    @csrf
    <div class="layui-form-item" style="margin-top: 20px">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-inline">
            <input type="number" name="phone" required  lay-verify="required" placeholder="请输入手机号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码框</label>
        <div class="layui-input-inline">
            <input type="password" name="pwd" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="login();">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <div class="layui-form-item" style="margin-top: 30px">
        <div class="layui-input-block">
            <a href="javascript:;" onclick="register();" style="margin-right: 20px;margin-left: 5px">注册账号</a>
            <a href="javascript:;" onclick="forget();">忘记密码</a>
        </div>
    </div>
</div>
<script type="text/javascript">
    layui.use(['layer'],function () {
        $ = layui.jquery;
    });
    //登录
    function login() {
        var phone = $.trim($('input[name="phone"]').val());
        var pwd      = $.trim($('input[name="pwd"]').val());
        var _token   = $('input[name="_token"]').val();
        if (phone==''){
            return layer.alert('请输入手机号',{icon:2});
        }
        if (pwd==''){
            return layer.alert('请输入密码',{icon:2});
        }

        $.post('/home/login/dologin',{_token:_token,phone:phone,pwd:pwd},function (res) {
            if (res.code>0){
                return layer.alert(res.msg,{icon:2});
            }
            layer.msg(res.msg);
            setTimeout(function () {

                parent.window.location.href = '/';
            },1000);

        },'json');
    }
    function keyLogin(){
        if (event.keyCode==13)  //回车键的键值为13
            document.getElementById("subBtn").click(); //调用登录按钮的登录事件
    }
    function register() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.title('用户注册', index)
        window.location.href = '/home/login/phoneregister';
    }
    function forget() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.title('忘记密码', index)
        window.location.href = '/home/phoneforget';

    }
</script>
</body>
</html>
